import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import weerapp.meet.Meetgegevens;

@SuppressWarnings("serial")
public class GrafiekView extends JPanel {
	private GrafiekPanel grafiekPanel;
	private ComboPanel comboPanel;
	private Meetgegevens meetgegevens;
	private ComboListener comboListener;

	public GrafiekView() {
		meetgegevens = new Meetgegevens("Data/twente.txt");
		setLayout(new BorderLayout());
		grafiekPanel = new GrafiekPanel(meetgegevens);
		comboPanel = new ComboPanel();

		comboListener = new ComboListener();
		comboPanel.comboJaar.addActionListener(comboListener);
		comboPanel.comboMaand.addActionListener(comboListener);

		add(comboPanel, BorderLayout.NORTH);
		add(grafiekPanel, BorderLayout.CENTER);

		grafiekPanel.setPanel(comboPanel.intMaand, comboPanel.intJaar);
	}

	public void Sync(int aMaand, int aJaar) {
		comboPanel.intMaand = aMaand;
		comboPanel.intJaar = aJaar;
		comboPanel.comboJaar.setSelectedItem(Integer.toString(aJaar));
		comboPanel.comboMaand.setSelectedIndex(aMaand-1);
	}

	public int getMaand() {
		return comboPanel.intMaand;
	}

	public int getJaar() {
		return comboPanel.intJaar;
	}

	class ComboListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			if (e.getSource() == comboPanel.comboJaar) {
				comboPanel.intJaar = comboPanel.comboJaar.getSelectedIndex() + 2001;
			}
			if (e.getSource() == comboPanel.comboMaand) {
				comboPanel.intMaand = comboPanel.comboMaand.getSelectedIndex() + 1;
			}
			grafiekPanel.setPanel(comboPanel.intMaand, comboPanel.intJaar);
			revalidate();
			repaint();
		}
	}
}
